package com.jhgk.jhcee.queue.controller;

import com.jhgk.jhcee.common.resultful.BasisResultful;
import com.jhgk.jhcee.queue.config.RabbitMqConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/13 16:37.
 */
@RestController
@Api(value = "消息",tags = {"消息"})
public class MqMessageController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMessage")
    @ApiOperation("发送消息")
    public BasisResultful<Object> sendMessage(String message) {
        Map<String,Object> messageMap = new HashMap<>();
        String messageId = String.valueOf(UUID.randomUUID());
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        messageMap.put("messageId",messageId);
        messageMap.put("messageData",message);
        messageMap.put("createTime",createTime);
        rabbitTemplate.convertAndSend(RabbitMqConfig.TOPIC_EXCHANGE,RabbitMqConfig.TOPIC_ROUTINGKEY_ONE,messageMap);
        return BasisResultful.success();
    }

}
